var fofo = document.getElementsByClassName("f1");

console.log(fofo);
console.log(document.getElementsByTagName('p'));
//在ie678就用这个方法
function getElementsByClassname(classname,context){
    var arr  =[];
    //如果context为undefined则context = document.
    context = context || document;
    var NodeList = context.getElementsByTagName('*');
    console.log(NodeList);
    //
    var ary = classname.replace(/(^ +| +$)/g,'').split(/ +/);
    console.log(ary);
    
    for(var i = 0; i < NodeList.length; i++){
        var isOk = true;
        var curNode = NodeList[i];
        for(var j = 0; j < ary.length; j++){
            var curClass = ary[j];
            var reg = new RegExp('(^| +)' + curClass + '($| +)');
            if(!reg.test(curNode.className)){
                isOk = false;
                break;
            }
        }

        if(isOk){
            arr.push(curNode);
        }
        
        
    }

    return arr;
}

var ary = getElementsByClassname("   f2 ");

console.log(ary);

